<?php
/**
 * Created by PhpStorm.
 * User: hebidu
 * Date: 2017-10-10
 * Time: 17:27
 */

namespace app\src\sunsun\common\helper;

use sunsun\po\BaseReqPo;

class DelayStaticsHelper
{
    /*
     * 统计的最大数量
     */
    const STATICS_COUNT_MAX = 3;

    public static function init($session, BaseReqPo $req)
    {
        if (empty($session)) {
            return [];
        }
        $delay = [];
        if (array_key_exists('delay', $session) && is_array($session['delay'])) {
            $delay = $session['delay'];
        }
        if (count($delay) > self::STATICS_COUNT_MAX) {
            array_pop($delay);
        }
        array_unshift($delay, ['sn' => $req->getSn(), 's' => microtime(true)]);
        return ['delay' => $delay];
    }
}